<!--
 * @Description: 
 * @Author: mmzhang
 * @Date: 2022-01-12 14:44:24
 * @LastEditTime: 2022-01-18 14:25:26
-->
<template>
  <div class="building_configure">
    <div class="build_alise">
      <div class="build_alise_warp">
        <span>{{ buildMess.housesName }}</span>
        <span class="houses_edit" @click="housesEditFlag = true" v-if="unlocking('0102010106')">修改</span>
        <div class="housesId_txt">楼盘ID:{{ buildMess.housesId }}</div>
      </div>
      <div>
        <Button type="primary" class="operation" v-if="operationBtnFlag" @click="operationClick">
          Sop操作日志
        </Button>
        <Button type="primary" @click="copyBuildFun" style="margin-left: 15px" v-if="unlocking('0102011000')">
          案场复制
        </Button>
        <Button type="primary" style="margin-left: 15px">
          <a
            href="https://images.tospurfang.com/doc/%E6%A1%88%E5%9C%BA%E9%85%8D%E7%BD%AE%E6%93%8D%E4%BD%9C%E8%AF%B4%E6%98%8E.pdf"
            style="color: #fff"
            target="_blank">
            查看操作指引
          </a>
        </Button>
      </div>
    </div>

    <Tabs
      ref="nav"
      type="card"
      v-model="personalInformation"
      :animated="false"
      @on-click="tabValChange"
      name="personalInformation">
      <TabPane class="tab_pane" label="基础信息" name="basicInformation" v-if="unlocking('0102010100')">
        <basic-information
          v-if="personalInformation === 'basicInformation'"
          tab="personalInformation"
          ref="basicInformationRef" />
      </TabPane>

      <TabPane label="开盘批次" name="openingBatch" v-if="unlocking('0102010200')">
        <opening-batch v-if="personalInformation === 'openingBatch'" tab="personalInformation" />
      </TabPane>

      <TabPane label="本案台账" name="buildingFileld" v-if="unlocking('0102010300')">
        <building-fileld v-if="personalInformation === 'buildingFileld'" tab="personalInformation" />
      </TabPane>

      <TabPane label="渠道配置" name="caseChannelList" v-if="unlocking('0102010400')">
        <case-channelList v-if="personalInformation === 'caseChannelList'" tab="personalInformation" />
      </TabPane>

      <TabPane label="银行配置" name="bankList" v-if="unlocking('0102010500')">
        <bank-list v-if="personalInformation === 'bankList'" tab="personalInformation" />
      </TabPane>

      <TabPane label="目标管理" name="targetManagement" v-if="unlocking('0102010600')">
        <target-config v-if="personalInformation === 'targetManagement'" tab="personalInformation" />
      </TabPane>

      <TabPane label="Sop配置" name="SOPManagement" v-if="unlocking('0102010700')">
        <SOP-management v-if="personalInformation === 'SOPManagement'" tab="personalInformation" />
      </TabPane>
      <TabPane label="抢客配置" name="robOpt" v-if="unlocking('0102010900')">
        <robOpt v-if="personalInformation === 'robOpt'" tab="personalInformation" />
      </TabPane>
      <TabPane label="合同管理" name="contract" v-if="unlocking('0102010800')">
        <contract v-if="personalInformation === 'contract'" tab="personalInformation" />
      </TabPane>

      <TabPane label="案场资料" name="buildingFile" v-if="unlocking('0102011100')">
        <buildingFile v-if="personalInformation === 'buildingFile'" tab="personalInformation" />
      </TabPane>
      <TabPane label="商务点数设置" name="bizPoint" v-if="unlocking('0102011200')">
        <bizPoint v-if="personalInformation === 'bizPoint'" tab="personalInformation" />
      </TabPane>
    </Tabs>
    <Modal v-model="housesEditFlag" title="修改楼盘名称" footer-hide>
      <Form ref="housesNameEdit" :model="formValidate" :rules="ruleValidate" :label-width="130">
        <Row :gutter="10">
          <Col span="20">
            <FormItem label="楼盘名称:" prop="housesName">
              <Input type="text" v-model="formValidate.housesName"></Input>
            </FormItem>
          </Col>
        </Row>
        <Row type="flex" justify="end">
          <Col span="8" class="cityList_moudle_footer">
            <Button @click="housesEditFlag = false">取消</Button>
            <Button
              style="marginleft: 20px"
              type="primary"
              @click="onOk('formValidate')"
              :loading="onOkloading">
              确定
            </Button>
          </Col>
        </Row>
      </Form>
      <operation-record ref="operationRecord"></operation-record>
    </Modal>
    <!--案场复制-->
    <dt-modal-edit ref="copyEdit" title="案场复制" @ok="onCopyOk"></dt-modal-edit>
    <!--案场复制提示信息-->
    <dt-modal-info ref="copyTips" title="提示">
      <p v-for="(item, index) in failTips" :key="index" style="line-height: 26px">
        {{ index + 1 }}、{{ item }}
      </p>
    </dt-modal-info>
  </div>
</template>

<script>
  import basicInformation from './components/basicInformation/index.vue'
  import openingBatch from './components/openingBatch/openingBatch.vue'
  import buildingFileld from './components/buildingField/buildingField.vue'
  import caseChannelList from './components/caseChannel/caseChannelList.vue'
  import targetConfig from './components/targetConfig/index.vue'
  import bankList from './components/bankDeploy/bankList.vue'
  import SOPManagement from './components/SOP'
  import contract from './components/contract/index.vue'
  import robOpt from './components/robOpt/index.vue'
  import bizPoint from './components/bizPoint/index.vue'
  import buildingFile from './components/buildingFile/index.vue'
  import buildMgr from '@/biz/building'
  import buildingApi from '@/biz/buildingManagement/basicInfo'
  import copyOpt from './components/copyBuild'
  let tabName = ''

  export default {
    components: {
      basicInformation,
      openingBatch,
      buildingFileld,
      caseChannelList,
      bankList,
      targetConfig,
      targetConfig,
      SOPManagement,
      contract,
      robOpt,
      bizPoint,
      buildingFile
    },
    data() {
      return {
        operationBtnFlag: false,
        personalInformation: 'basicInformation',
        buildMess: {}, //楼盘名称
        housesEditFlag: false,
        onOkloading: false,
        formValidate: {
          housesName: this.$dt.buildInfo().housesName
        },
        ruleValidate: { housesName: [{ required: true, message: '请输入楼盘名称' }] },
        copyInfo: {
          targetBuildingId: this.$dt.buildInfo().housesId,
          sourceBuildingId: '',
          copyTypes: []
        },
        failTips: []
      }
    },
    methods: {
      // 案场复制
      copyBuildFun() {
        this.copyInfo = {
          targetBuildingId: this.$dt.buildInfo().housesId,
          sourceBuildingId: '',
          copyTypes: []
        }
        this.$refs.copyEdit.show(new copyOpt(this), this.copyInfo)
      },
      onCopyOk() {
        buildingApi.buildingCopyFun(this.copyInfo).then((res) => {
          this.$refs.basicInformationRef && this.$refs.basicInformationRef.init()
          this.$refs.copyEdit.hide()
          if (res.failMessages.length) {
            this.failTips = res.failMessages
            this.$refs.copyTips.show()
          }
        })
      },
      operationClick() {
        this.$refs.operationRecord.show('operation_sopCase', 'M_3', this.$dt.buildInfo().housesId)
      },
      tabValChange(val) {
        console.log(val, 'vvvv')
        tabName = val
        if (val == 'SOPManagement') {
          this.operationBtnFlag = true
        }
      },
      onOk() {
        this.$refs.housesNameEdit.validate((valid) => {
          if (valid) {
            this.onOkloading = true
            let params = {
              housesName: this.formValidate.housesName,
              housesId: this.$dt.buildInfo().housesId
            }
            buildingApi
              .housesEdit(params)
              .then((res) => {
                this.onOkloading = false
                this.housesEditFlag = false
                let obj = this.$dt.buildInfo()
                obj.housesName = params.housesName
                buildMgr.updateBuildInfo(obj)
                this.routerListAll = this.$store.state.routerList
                if (this.$tool.getStorage('isbuildFlag') == 'buildpage') {
                  this.buildAlise = obj ? obj.housesName : '案场首页'
                  if (this.routerListAll[0].name == 'buildingHome') {
                    this.$set(this.routerListAll[0].meta, 'title', this.buildAlise)
                  }
                }
              })
              .catch(() => {
                this.onOkloading = false
              })
          }
        })
      }
    },
    created() {
      this.buildMess = this.$dt.buildInfo()
      tabName = this.$route.params.fromCustomer || tabName
      this.personalInformation = tabName || 'basicInformation'
    }
  }
</script>
<style lang="scss" scoped>
  .building_configure {
    padding: 0 15px;

    .build_alise {
      font-size: 26px;
      line-height: 30px;
      padding: 20px 10px;
      display: flex;
      justify-content: space-between;

      .build_alise_warp {
        .houses_edit {
          margin-left: 10px;
          font-size: 15px;
          color: #2d8cf0;
          cursor: pointer;
        }

        .housesId_txt {
          font-size: 18px;
        }
      }
    }

    .cityList_moudle_footer {
      display: flex;
      justify-content: space-around;
      margin-top: 20px;
      margin-bottom: 20px;
    }

    ::v-deep .ivu-tabs-bar {
      padding-left: 20px;
    }
  }
</style>
